import logging
from abc import ABC, abstractmethod
from django.conf import settings

logger = logging.getLogger(__name__)

class SMSProvider(ABC):
    @abstractmethod
    def send(self, phone: str, code: str, purpose: str) -> bool:
        pass

class AliyunSMS(SMSProvider):
    def send(self, phone, code, purpose):
        try:
            # 实际调用阿里云SDK
            print(f"[阿里云] 发送至 {phone}: {code}（{purpose}）")
            return True
        except Exception as e:
            logger.error(f"Aliyun SMS失败: {e}")
            return False

class MockSMS(SMSProvider):
    def send(self, phone, code, purpose):
        print(f"[模拟] 发送至 {phone}: {code}（{purpose}）")
        return True

def get_sms_provider() -> SMSProvider:
    provider_map = {
        'aliyun': AliyunSMS(),
        'mock': MockSMS()
    }
    return provider_map.get(settings.SMS_PROVIDER, MockSMS())